import os

# 初始化
process_next = False
is_d = False
is_e = False

def dialogue_text(input_file, output_file):
    with open(input_file, "r") as f:
        lines = f.readlines()
    output = ""
    for line in lines:
        if line.startswith("#d"):
            # 以#d开头，表示要跳过该行，同时说明下一行是描述
            process_next = True
            is_d = True
        elif process_next and is_d:
            output += "{{Lang=en-US;olivia}}\n" + line + "\n{{Pause=500}}\n"
            # Reset the flag
            process_next = False
            is_d = False

        elif line.startswith("#e"):
            # 以#e开头，表示要跳过该行，同时说明下一行是例子
            process_next = True
            is_e = True
        elif process_next and is_e:
            speaker_list = ["michael_expressive", "emma_expressive", "james", "charlotte"]
            for i in range(0, 4):
                output += "{{Lang=en-US;" + speaker_list[i % 4] + "}}\n" + line + "\n{{Pause=500}}\n"
            # Reset the flag
            process_next = False
            is_e = False

    with open(output_file, "w") as f:
        f.write(output)

# 获取该.py文件的绝对路径，如：d:\vocabulary\text.py
current_file_path = os.path.abspath(__file__)
# 获取该.py文件所在路径，如：d:\vocabulary
current_directory = os.path.dirname(current_file_path)

# 输入文件：与该.py文件同一个文件夹下的input.txt
input_file = os.path.join(current_directory, "input.txt")
# 输出文件：与该.py文件同一个文件夹下的output.txt
output_file = os.path.join(current_directory, "output.txt")

dialogue_text(input_file, output_file)


